<template>
  <el-header>
    <div class="l-content">
      <el-button size="small" plain @click="handleCollapse">
        <el-icon :size="15">
          <Menu />
        </el-icon>
      </el-button>
      <el-breadcrumb separator="/" class="bread">
        <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item :to="currentMenu.path" v-if="currentMenu">
          {{ currentMenu.label }}</el-breadcrumb-item
        >
      </el-breadcrumb>
      <!-- <CommonBread /> -->
    </div>
    <div class="r-content">
      <el-dropdown>
        <span class="el-dropdown-link">
          <img class="user" :src="getImgScr('admin')" alt="" />
        </span>
        <template #dropdown>
          <el-dropdown-menu>
            <el-dropdown-item>个人中心</el-dropdown-item>
            <el-dropdown-item @click="handleLogout">退出</el-dropdown-item>
          </el-dropdown-menu>
        </template>
      </el-dropdown>
    </div>
  </el-header>
</template>

<script>
import { defineComponent, computed } from "vue";
import { useStore } from "vuex";
import { useRouter } from "vue-router";
// import CommonBread from "./CommonBread.vue";
export default defineComponent({
  setup() {
    let store = useStore();
    let router = useRouter();
    const getImgScr = (user) => {
      return new URL(`../assets/images/${user}.png`, import.meta.url).href;
    };
    let handleCollapse = () => {
      store.commit("updateCollapse");
    };
    const currentMenu = computed(() => {
      return store.state.currentMenu;
    });
    const handleLogout = () => {
      store.commit("clearMenu");
      store.commit("clearToken");
      router.push({
        name: "login",
      });
    };
    // const current = ref(null);
    // watch(
    //   currentMenu,
    //   (newValue, oldValue) => {
    //     console.log("watch 已触发", newValue);
    //     current.value = newValue;
    //     console.log(current);
    //   },
    //   { deep: true }
    // );
    return {
      getImgScr,
      handleCollapse,
      currentMenu,
      handleLogout,
    };
  },
});
</script>

<style lang="less" scoped>
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  background: #333;
}
.r-content {
  .user {
    width: 40px;
    height: 40px;
    border-radius: 50%;
  }
}
.l-content {
  display: flex;
  align-items: center;
  .el-button {
    margin-right: 20px;
  }
  h3 {
    color: #fff;
  }
}
.bread :deep(span) {
  color: #fff !important;
  cursor: pointer !important;
}
</style>
